﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DTOs
{
    public class InvoiceItemDTO
    {
        
    #region Properties

    private ProductDTO _invoiceItemProduct = new ProductDTO();

    private string _invoiceId = "";
    /// <summary>
    /// SessionId unless pulling database ID
    /// </summary>
    public string InvoiceId
    {
        get
        {
            return _invoiceId;
        }
        set
        {
            _invoiceId = value;
        }
    }

    public string ProductId
    {
        get
        {
            return _invoiceItemProduct.ProductCode;
        }
        set
        {
            _invoiceItemProduct = new ProductDTO(value);
        }
    }

    public string ProductName
    {
        get
        {
            return _invoiceItemProduct.Name;
        }
    }

    private int _quantity = 0;
    public int Quantity
    {
        get
        {
            return _quantity;
        }
        set
        {
            _quantity = value;
        }
    }

    public decimal Price
    {
        get
        {
            return _invoiceItemProduct.Price * Quantity;
        }
    }

    public decimal UnitPrice
    {
        get
        {
            return _invoiceItemProduct.Price;
        }
    }

    public decimal ShippingCost
    {
        get
        {
            return _invoiceItemProduct.Shipping;
        }
    }

    public decimal HandlingCost
    {
        get
        {
            return _invoiceItemProduct.Handling;
        }
    }

    //private decimal _taxRate = decimal.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["taxRate"].ToString());
    private decimal _taxRate = 0;

    /// <summary>
    /// Retrieve taxes - if this is a taxable product
    /// </summary>
    public decimal Taxes
    {
        get
        {
            if (_invoiceItemProduct.Taxable)
            {
                return this.UnitPrice * (_taxRate / 100M) * this.Quantity;
            }
            else
            {
                return 0M;
            }
        }
    }

    #endregion

    public InvoiceItemDTO()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public InvoiceItemDTO(string invoiceId, string productId, int quantity)
    {
        this.InvoiceId = invoiceId;
        this.ProductId = productId;
        this.Quantity = quantity;
    }

    public void UpdateQuantity(int quantity)
    {
        this.Quantity = quantity;
    }

    public void AddToQuantity(int quantity)
    {
        this.Quantity += quantity;
    }
    

    }
}
